/*
 * @Description: 
 * @Date: 2024-04-28 09:16:39
 * @LastEditTime: 2024-04-28 10:40:04
 */
import quan from "../../../../assets/images/digitzation/quan.png";
import nan from "../../../../assets/images/digitzation/nan.png";
import nv from "../../../../assets/images/digitzation/nv.png";
export function pie1Data(params) {
    var echartData = [
        {
            value: 0,
            name: "农民",
            id: 1,
        },
        {
            value: 0,
            name: "干部",
            id: 2
        },
        {
            value: 0,
            name: "企业经营者",
            id: 6
        },
        {
            value: 0,
            name: "知识分子",
            id: 4
        },
        {
            value: 0,
            name: "工人",
            id: 3
        },
        {
            value: 0,
            name: "专技人员",
            id: 5
        },
    ];
    let num = params.length > 0 && params.reduce(
        (accumulator, currentValue) => accumulator + Number(currentValue.count),
        0,
    );
    params.length > 0 && echartData.forEach((item) => {
        for (var i = 0; i < params.length; i++) {
            if (item.id == params[i].postType) {
                item.value = params[i].count;
            }
        }
    });
    var rich = {
        total: {
            color: "#ffc72b",
            fontSize: 18,
            align: "center",
        },
        white: {
            color: "#fff",
            align: "center",
            fontSize: 18,
            padding: [5, 10],
        },
        blue: {
            color: "#49dff0",
            fontSize: 14,
            align: "center",
        },
        hr: {
            borderColor: "#0b5263",
            width: "100%",
            borderWidth: 1,
            height: 0,
        },
    };
    let option = {
        title: {
            text: num,
            subtext: "总代表数",
            textStyle: {
                fontSize: 18,
                color: "#ffc72b",
                fontWeight: "bold",
            },
            subtextStyle: {
                fontSize: 20,
                color: "#fff",
                fontWeight: 600,
            },
            textAlign: "center", //图例文字居中显示
            x: "49%", //距离左边的距离
            y: "45%", //距离上边的距离
        },
        series: [
            {
                name: "总考生数量",
                type: "pie",
                radius: ["40%", "60%"],
                hoverAnimation: false,
                color: [
                    "#c487ee",
                    "#deb140",
                    "#49dff0",
                    "#034079",
                    "#6f81da",
                    "#00ffb4",
                ],
                label: {
                    normal: {
                        formatter: function (params, ticket, callback) {
                            var total = 0; //考生总数量
                            var percent = 0; //考生占比
                            echartData.forEach(function (value, index, array) {
                                total += value.value;
                            });
                            percent = ((params.value / total) * 100).toFixed(1);
                            return (
                                "{white|" +
                                params.name +
                                "}\n{hr|}\n\n{blue|" +
                                params.value +
                                "}"
                            );
                        },
                        rich: rich,
                    },
                },
                labelLine: {
                    normal: {
                        length: 30,
                        length2: 0,
                        lineStyle: {
                            color: "#0b5263",
                        },
                    },
                },
                data: echartData,
            },
        ],
    }
    return params.length > 0 ? {
        option,
        echartData,
        num
    } : null
}

export function pieData2(params) {
    const color = ["#00FFFF", "rgba(196,36,255,1)"];
    const res = [
        {
            label: "男",
            value: 0,
            sex: 1
        },
        {
            label: "女",
            value: 0,
            sex: 0
        },
    ];
    params.length > 0 && res.forEach((item) => {
        for (var i = 0; i < params.length; i++) {
            if (item.sex == params[i].sex) {
                item.value = params[i].count;
            }
        }
    });
    const data1 = [];
    for (let i = 0; i < res.length; i++) {
        data1.push(
            {
                value: res[i].value,
                name: res[i].label,
                itemStyle: {
                    borderWidth: 5,
                    shadowBlur: 20,
                    borderColor: color[i],
                    shadowColor: color[i],
                },
            },
            {
                value: res[0].value / 10,
                name: res[i].label,
                label: {
                    show: false,
                },
                labelLine: {
                    show: false,
                },
                itemStyle: {
                    color: "rgba(0, 0, 0, 0)",
                    borderColor: "rgba(0, 0, 0, 0)",
                    borderWidth: 0,
                },
            }
        );
    }
    let option = {
        color: ["#00FFFF", "rgba(196,36,255,1)"],
        legend: {
            bottom: "0%",
            left: "center",
            textStyle: {
                color: "#fff",
            },
            orient: "horizontal",
        },
        graphic: {
            elements: [
                {
                    type: "image",
                    z: 3,
                    style: {
                        image: quan,
                        width: 180,
                        height: 180,
                    },
                    left: "center",
                    top: "center",
                    position: [100, 100],
                },
                {
                    type: "image",
                    z: 3,
                    style: {
                        image: nan,
                        width: 50,
                        height: 80,
                    },
                    left: "36%",
                    top: "center",
                },
                {
                    type: "image",
                    z: 3,
                    style: {
                        image: nv,
                        width: 50,
                        height: 80,
                    },
                    right: "36%",
                    top: "center",
                },
            ],
        },
        tooltip: {
            show: false,
        },
        toolbox: {
            show: false,
        },
        series: [
            {
                name: "",
                type: "pie",
                clockwise: false,

                radius: [115, 120],
                hoverAnimation: false,
                label: {
                    show: true,
                    fontSize: 16,
                    color: "#fff",
                    formatter(params) {
                        return params.name
                            ? params.name + "\n\n\n" + params.value + "人"
                            : "";
                    },
                },
                labelLine: {
                    width: 1,
                    length: 20,
                    length2: 10,
                    show: true,
                    color: "#ffff",
                },

                data: data1,
            },
        ],
    };
    return params.length > 0 ? option : null
}

export function pieData3(params, type) {
    let data = [];
    if (type == 'party') {
        data = [
            { value: 0, name: "中共党员", id: 1 },
            { value: 0, name: "九三学社社员", id: 2 },
            { value: 0, name: "民联会员", id: 3 },
            { value: 0, name: "民法会员", id: 4 },
            { value: 0, name: "民革会员", id: 5 },
        ]
        params.length > 0 && data.forEach((item) => {
            for (var i = 0; i < params.length; i++) {
                if (item.id == params[i].party) {
                    item.value = params[i].count;
                }
            }
        });
    } else {
        data = [
            { value: 0, name: "初中", id: 1 },
            { value: 0, name: "高中", id: 2 },
            { value: 0, name: "中专", id: 3 },
            { value: 0, name: "大专", id: 4 },
            { value: 0, name: "本科", id: 6 },
            { value: 0, name: "研究生", id: 7 },
        ]
        params.length > 0 && data.forEach((item) => {
            for (var i = 0; i < params.length; i++) {
                if (item.id == params[i].qualification) {
                    item.value = params[i].count;
                }
            }
        });
    }
    let option = {
        tooltip: {
            trigger: "item",
        },
        legend: {
            bottom: "5%",
            left: "center",
            textStyle: {
                color: "#fff",
                fontSize: 16,
            },
            orient: "horizontal",
        },
        series: [
            {
                name: "Access From",
                type: "pie",
                radius: "50%",
                center: ["50%", "40%"],
                data: data,
                label: {
                    color: "#fff",
                    fontSize: 18,
                },
                itemStyle: {
                    normal: {
                        shadowBlur: 200,
                        shadowColor: "rgba(0, 0, 0, 0.5)",
                    },
                },
                emphasis: {
                    itemStyle: {
                        shadowBlur: 10,
                        shadowOffsetX: 0,
                        shadowColor: "rgba(0, 0, 0, 0.5)",
                    },
                },
            },
        ],
    }
    return params.length > 0 ? option : null
}

export function pieData4(params, types) {
    let data = [
        {
            value: 100,
            name: "汉族",
        },
        {
            value: 100,
            name: "壮族",
        },
        {
            value: 100,
            name: "瑶族",
        },
    ];
    data = params.length > 0 && params.map((item) => {
        return {
            value: item.count,
            name: types[Number(item.nationality)]['label']
        }
    })
    let option = {
        tooltip: {
            trigger: "item",
            formatter: "{a} <br/>{b}: {c} ({d}%)",
        },
        legend: {
            orient: "horizontal",
            icon: "circle",
            bottom: 20,
            x: "center",
            textStyle: {
                color: "#fff",
                fontSize: 16,
            },
            data: data.length > 0 ? data.map(item => item.name) : [],
        },
        series: [
            {
                name: "访问来源",
                type: "pie",
                selectedMode: "single",
                radius: [0, "38%"],
                center: ["50%", "40%"],
                label: {
                    normal: {
                        show: false,
                        position: "inner",
                        formatter: "{d}%",
                        textStyle: {
                            color: "#fff",
                            fontWeight: "normal",
                            fontSize: 16,
                        },
                    },
                },
                labelLine: {
                    normal: {
                        show: false,
                    },
                },
                data,
            },
            {
                name: "访问来源",
                type: "pie",
                center: ["50%", "40%"],
                radius: ["40%", "42%"],
                label: {
                    normal: {
                        formatter: "{b|{b}}\n{hr|}\n{d|{d}%}",
                        rich: {
                            b: {
                                fontSize: 18,
                                color: "#fff",
                                align: "left",
                                padding: [10, 5],
                            },
                            hr: {
                                borderColor: "#12EABE",
                                width: "100%",
                                borderWidth: 2,
                                height: 0,
                            },
                            d: {
                                fontSize: 18,
                                color: "#fff",
                                align: "left",
                                padding: [10, 5],
                            },
                            c: {
                                fontSize: 20,
                                color: "#fff",
                                align: "center",
                                padding: 4,
                            },
                        },
                    },
                },
                labelLine: {
                    normal: {
                        show: true,
                        length: 20,
                        length2: 20,
                        lineStyle: {
                            type: "dashed",
                            width: 2,
                        },
                    },
                },
                data
            },
        ],
    }
    return params.length > 0 ? option : null
}